<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <label for="uname">姓名</label>
        <input type="text" id="uname" name="uname">
        <label for="age">年龄</label>
        <input type="text" id="age" name="age">
        <button>提交</button>
    </div>
    <div>
        <table class="tab">

        </table>
    </div>
    <script>
        var unameEle = document.getElementById("uname");
        var ageEle = document.getElementById("age");
        var btnEle = document.querySelector("button");
        var tabEle = document.querySelector(".tab");
        btnEle.onclick = function () {
            var arr = [unameEle.value,ageEle.value];
            var tr = document.createElement("tr");
            arr.forEach(function( item , key ){
                var td = document.createElement("td");
                td.innerHTML = item ;
                tr.appendChild(td);
            });
            var tdDel = document.createElement("td");
            var btnDel = document.createElement("button");
            btnDel.innerHTML = '删除' ;
            btnDel.onclick = function (){
                tr.remove();
            }
            tdDel.appendChild(btnDel);
            tr.appendChild(tdDel);
            tabEle.appendChild(tr);
        }
    </script>
</body>
</html>